package com.yyfax.common.recyclerview.adapter;

import android.content.Context;
import com.yyfax.common.recyclerview.base.ItemViewDelegate;
import com.yyfax.common.recyclerview.base.ItemViewDelegateManager;
import com.yyfax.common.recyclerview.base.ViewHolder;

import java.util.List;

/**
 * Created by zhy on 16/4/9.
 * 通用单一adapter
 */
public abstract class CommonAdapter<T> extends MultiItemTypeAdapter<T> {
	protected int mLayoutId;
	protected List<T> mData;

	public CommonAdapter(final int layoutId, List<T> data, ItemViewDelegateManager itemViewDelegateManager) {
		super(data, itemViewDelegateManager);
		mLayoutId = layoutId;
		mData = data;

		addItemViewDelegate(new ItemViewDelegate<T>() {
			@Override
			public int getItemViewLayoutId() {
				return layoutId;
			}

			@Override
			public boolean isForViewType(T item, int position) {
				return true;
			}

			@Override
			public void convert(ViewHolder holder, T t, int position) {
				CommonAdapter.this.convert(holder, t, position);
			}
		});
	}

	protected abstract void convert(ViewHolder holder, T t, int position);
}
